#include<bits/stdc++.h>

using namespace std;

const int N = 510, INF = 0x3f3f3f3f;
int dp[N][N];
int g[N][N];

int main() {
    int n;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            cin >> g[i][j];
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i + 1; j++) {          //因为有负数，所以应该将两边也设为-INF
            dp[i][j] = -INF;
        }
    }

    dp[1][1] = g[1][1];
    for (int i = 2; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j]) + g[i][j];
        }
    }

    int res = -INF;
    for (int i = 1; i <= n; ++i) {
        res = max(res, dp[n][i]);
    }
    cout << res << endl;
}
